package com.hcrazy.manchester.app.controllers.advert;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hcrazy.manchester.app.pojo.ErrorMsg;
import com.hcrazy.manchester.app.services.AdvertService;
import com.hcrazy.manchester.app.utils.Constant;
import com.hcrazy.manchester.app.utils.Log;

@Controller
@RequestMapping("/api/advert")
public class AdvertAPIController {

	@Autowired
	private AdvertService advertService;
	
	@RequestMapping(value="/start",produces=MediaType.APPLICATION_JSON_VALUE,method={RequestMethod.GET,RequestMethod.POST})
	public @ResponseBody Object getAdvertStart(){
		try {
			return advertService.getAdvertStart();
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/index",produces=MediaType.APPLICATION_JSON_VALUE,method={RequestMethod.GET,RequestMethod.POST})
	public @ResponseBody Object getAdvertIndex(){
		try {
			return advertService.getAdvertIndex();
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/list",produces=MediaType.APPLICATION_JSON_VALUE,method={RequestMethod.GET,RequestMethod.POST})
	public @ResponseBody Object getAdvertList(@RequestParam int moduleType){
		try {
			return advertService.getAdvertList(moduleType);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	
}
